package logic

import (
	"context"

	"diff.wang/asynqsrv/common"
	"diff.wang/asynqsrv/server/internal/svc"
	"github.com/hibiken/asynq"
)

type CronJob struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCronJob(ctx context.Context, svcCtx *svc.ServiceContext) *CronJob {
	return &CronJob{
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// register job
func (l *CronJob) Register() *asynq.ServeMux {

	mux := asynq.NewServeMux()

	// 定时任务
	mux.Handle(common.ScheduleComputerAdd, NewComputerAddTask())

	// 即时任务
	mux.Handle(common.MsgEmailDelivery, NewEmailDeliveryTask(l.svcCtx))
	mux.Handle(common.MsgPhoneDelivery, NewPhoneDeliveryTask(l.svcCtx))

	// 延时任务
	mux.Handle(common.DeferCloseOrder, NewCloseOrderTask(l.svcCtx))

	return mux
}
